<!--
 * @Descripttion: 换房
 * @version: 1.0
 * @Author: 狸猫
 * @Date: 2023-11-25 14:29:36
 * @LastEditors: 狸猫
 * @LastEditTime: 2024-01-10 15:00:38
-->
<template>
  <div class="content">
    <el-dialog
      :title="title"
      :visible.sync="visible"
      width="800px"
      append-to-body
      :before-close="close"
    >
      <el-descriptions title="订单信息">
        <el-descriptions-item label="承租人"
          >{{ orderInfo.reservationName }}/{{
            orderInfo.reservationPhone
          }}</el-descriptions-item
        >
        <el-descriptions-item label="证件号">{{
          orderInfo.reservationCardNumber
        }}</el-descriptions-item>
        <el-descriptions-item label="房间">{{
          orderInfo.fullAddress
        }}</el-descriptions-item>
      </el-descriptions>
      <el-form :model="form" ref="form" :inline="true">
        <el-form-item
          label="预计入住周期"
          prop="period"
          :rules="[
            { required: true, message: '请选择入住周期', trigger: 'change' },
          ]"
        >
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="form.period"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="onSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { updateReservationInfo } from "@/api/order/order";
export default {
  name: "orderEdit",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    orderInfo: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      title: "编辑预定信息",
      form: {
        checkInTime: "",
        checkOutTime: "",
        period: [],
      },
    };
  },
  created() {
    let period = [this.orderInfo.checkInTime, this.orderInfo.checkOutTime];
    this.form.period = period;
  },
  methods: {
    onSubmit() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.orderId = this.orderInfo.orderId;
          this.form.checkInTime = this.form.period[0];
          this.form.checkOutTime = this.form.period[1];
          updateReservationInfo(this.form).then((res) => {
            this.close();
            this.$message.success("操作成功");
          });
        }
      });
    },
    close() {
      this.$emit("closeeldialog");
    },
  },
};
</script>
<style lang="sasss" scoped></style>
